home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / LSEQ101.ZIP / LSSETBUF.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  89 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lssetbuf.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <blkio.h>
  11.  
  12. /* local headers */
  13. #include "lseq_.h"
  14.  
  15. /*man---------------------------------------------------------------------------
  16. NAME
  17.      lssetbuf - assign buffering to an lseq
  18.  
  19. SYNOPSIS
  20.      #include <lseq.h>
  21.  
  22.      int lssetbuf(lsp, buf)
  23.      lseq_t *lsp;
  24.      void *buf;
  25.  
  26. DESCRIPTION
  27.      The lssetbuf function causes the storage area pointed to by buf
  28.      to be used by the lseq associated with lseq pointer lsp instead
  29.      of an automatically allocated buffer area.  If buf is the NULL
  30.      pointer, lsp will be completely unbuffered.
  31.  
  32.      The size of the storage area needed can be obtained using the
  33.      LSBUFSIZE() macro:
  34.  
  35.           char buf[LSBUFSIZE(RECSIZE, LSBUFCNT)];
  36.           lssetbuf(lsp, (void *)buf);
  37.  
  38.      where RECSIZE is the size of the records in the lseq and LSBUFCNT
  39.      is the default number of records buffered when an lseq is opened.
  40.      LSBUFCNT is defined in <lseq.h>.  If the number of records
  41.      buffered has been changed using lssetvbuf, then that number
  42.      should be used in place of LSBUFCNT.
  43.  
  44.      lssetbuf may be called at any time after opening the lseq,
  45.      before and after it is read or written; the buffers are flushed
  46.      before installing the new buffer area.
  47.  
  48.      lssetbuf will fail if one or more of the following is true:
  49.  
  50.      [EINVAL]       lsp is not a valid lseq pointer.
  51.      [LSENBUF]      buf is not the NULL pointer and lsp
  52.                     is not buffered.
  53.      [LSENOPEN]     lsp is not open.
  54.  
  55. SEE ALSO
  56.      lssetvbuf, lssync.
  57.  
  58. DIAGNOSTICS
  59.      Upon successful completion, a value of 0 is returned.  Otherwise,
  60.      a value of -1 is returned, and errno set to indicate the error.
  61.  
  62. ------------------------------------------------------------------------------*/
  63. int lssetbuf(lsp, buf)
  64. lseq_t *lsp;
  65. void *buf;
  66. {
  67.     /* validate arguments */
  68.     if (!ls_valid(lsp)) {
  69.         errno = EINVAL;
  70.         return -1;
  71.     }
  72.  
  73.     /* check if not open */
  74.     if (!(lsp->flags & LSOPEN)) {
  75.         errno = LSENOPEN;
  76.         return -1;
  77.     }
  78.  
  79.     /* assign buffering */
  80.     if (bsetbuf(lsp->bp, buf) == -1) {
  81.         if (errno == BENBUF) errno = LSENBUF;
  82.         LSEPRINT;
  83.         return -1;
  84.     }
  85.  
  86.     errno = 0;
  87.     return 0;
  88. }
  89.